﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Save_Editor.Windows;
using Oroboros;
using Oroboros.Objects;
using Oroboros.Save_Data;

namespace Save_Editor.Controls
{
    /// <summary>
    /// Interaction logic for ctrlInventoryData.xaml
    /// </summary>
    public partial class ctrlInventoryData : UserControl
    {
        public ctrlInventoryData()
        {
            InitializeComponent();
        }

        private void bmChooseItem(object sender, SelectionChangedEventArgs e)
        {
            if (listItems.SelectedIndex == -1) return;
            ItemData.Item = listItems.SelectedItem as ItemSaveData;
        }

        private void bmNewItem(object sender, RoutedEventArgs e)
        {
            ItemData.Item = null;
        }

        private winNewItem myItem = null;
        private void bmAddItem(object sender, RoutedEventArgs e)
        {
            if (myItem == null)
            {
                myItem = new winNewItem();
                myItem.Closed += new EventHandler(myItem_Closed);
            }

            if (myItem.ShowDialog().Value)
            {
                InventorySaveData invData = (InventorySaveData)listItems.DataContext;
                invData.Items.Add(createdItem, true);
                ItemData.Item = null;
            }
            //listItems.ItemsSource = ((InventoryData)this.DataContext).Items;
        }

        private ItemSaveData createdItem = null;
        void myItem_Closed(object sender, EventArgs e)
        {
            createdItem = myItem.Item;
            myItem = null;
        }
    }
}